using TMPro;
using UnityEngine;

public class GameManager : MonoBehaviour
{ 
    [Header("Scource")]
    public bool isPlaying;
    public AudioSource levelMusic;
    //public BeatScrollor BS;
    public static GameManager instance;
    private GamemodeData _gamemodeData;

    public GameObject ezMap;
    public GameObject midMap;
    public GameObject hdMap;

    [Header("UI")]
    public float Score;
    public int Comble;
    public TMP_Text scoreText;
    public TMP_Text combleText;
    public int maxComble;

    public GameObject stopUIWindow;

    [Header("ScoreValue")]
    public int preferScore = 300 ;
    public float scoreForKey = 100;


    private void Awake()
    {

    }
    void Start()
    {
        Score = 0;
        Comble = 0;
        instance = this;
        _gamemodeData = GameObject.FindGameObjectWithTag("Data").GetComponent<GamemodeData>();

        if (_gamemodeData.mode == "easy")
        {
            ezMap.SetActive(true);
            midMap.SetActive(false);
            hdMap.SetActive(false);
        }
        else if (_gamemodeData.mode == "middle")
        {
            ezMap.SetActive(false);
            midMap.SetActive(true);
            hdMap.SetActive(false);
        }
        else if (_gamemodeData.mode == "hard")
        {
            ezMap.SetActive(false);
            midMap.SetActive(false);
            hdMap.SetActive(true);
        };
    }

    void Update()
    {

        if (!isPlaying)
        {

                isPlaying = true;
                //BS.isStart = true;

                levelMusic.Play();
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            stopUIWindowAtv();
        }
    }

    public void NoteHit()
    {
        Comble++;
        combleText.text = Comble.ToString();
        scoreText.text = Score.ToString();
        if (Comble > maxComble)
        {
            maxComble = Comble;
        }

    }
    public void NoteMiss()
    {
        combleText.text = "0";
        Comble = 0;
    }
    public void PreferHit()
    {
        Score += preferScore;
        NoteHit();
    }
    public void NormalHit()
    {
        Score += scoreForKey;
        NoteHit();
    }

    public void stopUIWindowAtv()
    {
        if(stopUIWindow.activeSelf == false)
        {
            stopUIWindow.SetActive(true);
            levelMusic.Pause();
            Time.timeScale = 0;
        }
        else
        {
            stopUIWindow.SetActive(false);
            levelMusic.UnPause();
            Time.timeScale = 1;
        }
    }
}
